#! /bin/bash

if [[ $(uname -m) == "x86_64" ]]
then
  wget --backups=0 "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-3.6.10.tgz"
  tar -zxf ./mongodb-linux-x86_64-ubuntu1604-3.6.10.tgz --strip-components=1
else
  IFS=" " read -a links <<< $(apt-get -y --print-uris install mongodb | egrep -o "https?://[^']+")
  for link in ${links[@]}
  do
    wget --backups=0 ${link}
  done

  IFS=" " read -a deb_pkgs <<< $(ls ./ | egrep "\.deb")
  for pkg in ${deb_pkgs[@]}
  do
    echo "Extracting ${pkg}..."
    dpkg-deb -R ${pkg} ./
  done

  mv usr/bin bin
fi
